<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:s="http://sduept.security.el/func"
	template="/template/template_dialog.xhtml">
	<ui:define name="head">
		<link href="/css/primefaces/menubase.css" rel="stylesheet" type="text/css" />
		<title>新建互查计划</title>
		<style type="text/css">
			.ui-treetable th {
			    font-weight: bold !important;
			    color:#333 !important;
			}
			.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
			    border: 1px solid #999;
			}
			.ui-selectonemenu .ui-selectonemenu-trigger, .ui-selectcheckboxmenu .ui-selectcheckboxmenu-trigger {
			    border-color: #fff !important;
			}
			.ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {
			    border: 1px solid #156090;
			    background: #3c8dbc;
			    color: #555;
			}
		</style>
		<script>
			$(function() {
				setHeight();
			})
			function setHeight() {
				var height = $(window).height();
				var dtHeight = height-108;
				$('.ui-treetable-scrollable-body').attr('style','height:'+dtHeight+'px');
				document.getElementsByClassName("ui-treetable-scrollable-body")[0].style.overflowY = "scroll";
			}
			//添加评价厂站弹窗
			var addStationIndex;
			function openAddInspectionStationSelectorDialog() {
				var src = "/ui/equipmentAssessment/assessmentplan/dialog/inspectionStation_selector.xhtml"
				addStationIndex = layer.open({
					type : 2,
					area : [ '600px', '650px' ],
					fixed : false, //不固定
					title : '添加评价厂站',
					maxmin : true,
					content : src,
				});
			}
			//选择模板弹窗
			var selectFormTemplateIndex;
			function openSelectFromTemplate() {
				var src = "/ui/equipmentAssessment/assessmentplan/dialog/selectFromTemplateDialog.xhtml";
				selectFormTemplateIndex = layer.open({
					type : 2,
					area : [ '700px', '650px' ],
					fixed : false, //不固定
					title : '选择模板',
					maxmin : true,
					content : src,
				});
			}
			/*打开组织机构人员选择器*/
			var userDialogIndex;
			function openUserChooseDialog() {
				userDialogIndex = layer.open({
					type : 2,
					maxmin : false,
					area : [ '420px', '90%' ],
					fixed : false,
					title : '人员选择器',
					content : '/ui/common/org_selector_user_single_layer.xhtml'
				});
			}
			/*子弹窗关闭返回处理函数*/
			function dialogReturn(index, data) {
				var params = [];
				data = eval("(" + data + ")");
				if (index == addStationIndex) {
					params.push({
						name : 'stationType',
						value : data.stationType
					}, {
						name : 'selectedInspectionStations',
						value : JSON.stringify(data.selectedInspectionStations)
					});
					onAddInspectionStationSelectorDialogReturn(params);

				}
				if (index == selectFormTemplateIndex) {
					params.push({
						name : 'selectedInspectionStations',
						value : JSON.stringify(data.selectedInspectionStations)
					});
					onSelectFromTemplateDialogReturn(params);

				}
				if (index == userDialogIndex) {
					params.push({
						name : 'className',
						value : data.className
					}, {
						name : 'userJson',
						value : data.data
					});
					onUserDialogReturn(params);
				}
			}
			/*关闭该弹窗并返回数据*/
			function closeAndSave(data) {
				//将对象转为JSON字符串
				data = JSON.stringify(data);
				var index = parent.layer.getFrameIndex(window.name);
				if (parent.dialogReturn) {
					parent.dialogReturn(index, data);
				}
				parent.layer.close(index);
			}
		</script>
	</ui:define>
 	
	<ui:define name="content">
	  <h:form id="basicForm">
	  	<p:growl id="msgs" showDetail="true" />
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
				<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
				<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
			</p:confirmDialog>
		<p:panelGrid cellpadding="5" style="width:100%;border-bottom: 1px solid #999;">
			<p:row>
            	<p:column>
            		<p:outputLabel value="评价名称*："></p:outputLabel>
            	</p:column>
            	<p:column>
            		<p:inputText id="planName" value="#{addOrEditInspectSelfPlanController.targetPlan.name}" style="width:100%">					
					 	<p:ajax event="keyup" />
					 </p:inputText>
            	</p:column>
            	<p:column>
            		<p:outputLabel value="评价时间："></p:outputLabel>
            	</p:column>
            	<p:column>
					 <p:calendar id="startTime"
						value="#{addOrEditInspectSelfPlanController.targetPlan.startTime}"
						pattern="yyyy-MM-dd" >
						<p:ajax event="dateSelect" />
					</p:calendar>至<p:calendar id="endTime"
						value="#{addOrEditInspectSelfPlanController.targetPlan.endTime}"
						pattern="yyyy-MM-dd">
						<p:ajax event="dateSelect" />
					</p:calendar> 
				</p:column>  
                <p:column>
                	<p:outputLabel value="负责人*："></p:outputLabel>
                </p:column>
                <p:column>
					<h:inputText disabled="true" id="responsible" value="#{addOrEditInspectSelfPlanController.targetPlan.responsible}" required="true"/>
					<p:commandButton value="选择" icon="ui-icon-extlink" style="font-size:12px" onclick="openUserChooseDialog()"/>
					<p:remoteCommand name="onUserDialogReturn" update=":basicForm:responsible" 
							actionListener="#{addOrEditInspectSelfPlanController.onUserDialogReturn}" />
				</p:column>
				<p:column style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);text-align: center;">
					<p:commandButton style="font-size:14px" icon="fa fa-floppy-o" value="保存草稿" 
						actionListener="#{addOrEditInspectSelfPlanController.saveAssessmentPlan()}" >
					</p:commandButton>
				</p:column>
            </p:row>
		</p:panelGrid>
	</h:form>
	<h:form id="inspectSelfTreeForm">
		<p:toolbar id="treeBtn">
			<f:facet name="left">
				<p:commandButton value="添加评价厂站" icon="fa fa-plus"
					onclick="openAddInspectionStationSelectorDialog()" />
				<p:remoteCommand name="onAddInspectionStationSelectorDialogReturn" update="inspectSelfInfo"
				 	actionListener="#{addOrEditInspectSelfPlanController.onAddInspectionStationSelectorDialogReturn()}" oncomplete="setHeight()"/>
				<p:commandButton value="选择模板" icon="fa fa-file-o"
					onclick="openSelectFromTemplate()" />
				<p:remoteCommand name="onSelectFromTemplateDialogReturn" update="inspectSelfInfo"
				 	actionListener="#{addOrEditInspectSelfPlanController.onSelectFromTemplateDialogReturn()}" oncomplete="setHeight()"/>
				<p:commandButton icon="fa fa-trash-o" value="删除" 
				 	disabled="#{addOrEditInspectSelfPlanController.disabledDelBtn()}" 
				 	actionListener="#{addOrEditInspectSelfPlanController.deleteSelectedNodes()}" 
				 	update="inspectSelfInfo treeBtn basicForm:msgs" oncomplete="setHeight()">
				 	<p:confirm header="提示" message="确定删除吗？" icon="ui-icon-alert" />
				</p:commandButton>			
			</f:facet>
		</p:toolbar>
		<p:treeTable id="inspectSelfInfo" value="#{addOrEditInspectSelfPlanController.root}" var="item" emptyMessage="请添加信息" nodeVar="node"
			selectionMode="checkbox" selection="#{addOrEditInspectSelfPlanController.selectedNodes}"
			scrollable="true" scrollHeight="0">
			<p:ajax event="select" update="inspectSelfTreeForm:treeBtn" />
			<p:ajax event="unselect" update="inspectSelfTreeForm:treeBtn" />
			<p:ajax event="collapse" />
			<p:column headerText="抽检变电站名称" style="width:30%">
	            <h:outputText style="color:green;margin-right:10px;" value="#{item.name}" rendered="#{node.type=='first'}"/>
	            <h:outputText style="color:blue;margin-right:10px;" value="#{item.name}" rendered="#{node.type=='second'}"/>
	            <h:outputText value="#{item.name}" rendered="#{node.type=='third'}"/>
	            
	            <!-- 添加供电局联系人信息 -->
				<p:commandLink class="fa fa-user-plus" rendered="#{node.type=='second'}" title="供电局联系人"
					oncomplete="PF('addOrEditStationPersonnalInfo').show()" actionListener="#{addOrEditInspectSelfPlanController.setSelectedSecondNode(node)}"
					update="addOrEditStationPersonnalInfoForm:addOrEditStationPersonnalInfo"/>
				<h:outputText value="#{item.stationPersonnel}（#{item.stationPersonnelPhone}）" rendered="#{node.type=='second' and item.stationPersonnel!=null}" 
					style="text-decoration:underline;color:red;margin-left:10px;"></h:outputText>
				<!-- 中调联系人信息 -->
				<p:commandLink class="fa fa-user-plus" rendered="#{node.type=='first'}" title="中调联系人"
					oncomplete="PF('addOrEditInspectionScopePersonnelInfo').show()" actionListener="#{addOrEditInspectSelfPlanController.setSelectedFirstNode(node)}"
					update="addOrEditInspectionScopePersonnelInfoForm:addOrEditInspectionScopePersonnelInfo"/>
				<h:outputText value="#{item.inspectionScopePersonnel}（#{item.inspectionScopePersonnelPhone}）" rendered="#{node.type=='first' and item.inspectionScopePersonnel!=null}" 
					style="text-decoration:underline;color:red;margin-left:10px;"></h:outputText>
	        </p:column>
	        <p:column headerText="检查专家名称" style="text-align:center">
				<p:inputText id="inspectionExpert" value="#{item.inspectExpert}" style="width:90%" rendered="#{node.type=='third'}">					
				 	<p:ajax event="blur" listener="#{addOrEditInspectSelfPlanController.onInspectExpertBlur(item)}"/>
				 </p:inputText>
	        </p:column>
	        <p:column headerText="专家联系电话" style="text-align:center">
	        	<p:inputText id="inspectExpertPhone" value="#{item.inspectExpertPhone}" style="width:90%" rendered="#{node.type=='third'}">					
				 	<p:ajax event="blur" listener="#{addOrEditInspectSelfPlanController.onInspectExpertPhoneBlur(item)}"/>
				 </p:inputText>
	        </p:column>
	        <p:column headerText="开始时间" style="text-align:center">
	        	<p:calendar id="instation-startTime" rendered="#{node.type=='third'}"
					value="#{item.startTime}"
					pattern="yyyy-MM-dd" >
					<p:ajax event="dateSelect" listener="#{addOrEditInspectSelfPlanController.onStartDataSelect(item)}"/>
				</p:calendar>
	        </p:column>
	        <p:column headerText="结束时间" style="text-align:center">
	        	<p:calendar id="instation-endTime" rendered="#{node.type=='third'}"
					value="#{item.endTime}"
					pattern="yyyy-MM-dd" >
					<p:ajax event="dateSelect" listener="#{addOrEditInspectSelfPlanController.onEndDataSelect(item)}"/>
				</p:calendar>
	        </p:column>
	        <!-- <p:column headerText="派出专家单位" style="text-align:center">
	            <h:outputText value="#{item.inspectionUnit}" />
	            <p:autoComplete id="inspectionUnit" value="#{item.inspectionUnit}" scrollHeight="200" rendered="#{node.type=='third'}"
					dropdown="true" inputStyle="width:100%">
					<p:ajax event="itemSelect" />
					<p:ajax event="blur"  />
				</p:autoComplete>
				<p:inputText id="inspectionUnit" value="#{item.inspectionUnit}" style="width:90%" rendered="#{node.type=='third'}">					
				 	<p:ajax event="blur" listener="#{addOrEditInspectSelfPlanController.onInspectionUnitBlur(item)}"/>
				 </p:inputText>
	        </p:column> -->
	        <p:column headerText="抽检变电站类型" style="text-align:center">
	            <!-- <h:outputText value="#{item.stationType}" /> -->
	            <!-- <p:autoComplete id="stationName" value="#{item.stationType}" scrollHeight="200" rendered="#{node.type=='third'}"
					completeMethod="#{addOrEditInspectSelfPlanController.completeStationTypes}" dropdown="true" inputStyle="width:100%">
					<p:ajax event="itemSelect" listener="#{addOrEditInspectSelfPlanController.onStationTypeChanged(item)}"></p:ajax>
					<p:ajax event="keyup"></p:ajax>
				</p:autoComplete> -->
				<p:selectOneMenu id="stationType" value="#{item.stationType}" rendered="#{node.type=='third'}"
					style="font-weight:bold;width:90%">
					<f:selectItems value="#{addOrEditInspectSelfPlanController.completeStationTypes()}" var="type" itemLabel="#{type}"/>
					<p:ajax event="itemSelect" listener="#{addOrEditInspectSelfPlanController.onStationTypeChanged(item)}" />
				</p:selectOneMenu>
	        </p:column>
		</p:treeTable>
	</h:form>
	<h:form id="addOrEditStationPersonnalInfoForm">
		<p:dialog id="addOrEditStationPersonnalInfo" widgetVar="addOrEditStationPersonnalInfo" width="450" height="200"
			header="供电局联系人">
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="保存" icon="ui-icon-disk" 
						actionListener="#{addOrEditInspectSelfPlanController.saveOrUpdateStationPersonnalInfo}"
						oncomplete="PF('addOrEditStationPersonnalInfo').hide();setHeight()"
						update="inspectSelfTreeForm:inspectSelfInfo"/>
				</f:facet>
			</p:toolbar>
			<p:outputPanel style="text-align:center;">
				<p:panelGrid style="text-align:center;margin: 10px;width: 95%">
					<p:row>
						<p:column>
							<h:outputText value="联系人：" />
						</p:column>
						<p:column colspan="3">
							<h:inputText style="width:90%" value="#{addOrEditInspectSelfPlanController.stationPersonnel}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="联系电话：" />
						</p:column>
						<p:column colspan="3">
							<h:inputText style="width:90%" value="#{addOrEditInspectSelfPlanController.stationPersonnelPhone}" />
						</p:column>
					</p:row>
				</p:panelGrid>
			</p:outputPanel>
		</p:dialog>
	</h:form>
	<h:form id="addOrEditInspectionScopePersonnelInfoForm">
		<p:dialog id="addOrEditInspectionScopePersonnelInfo" widgetVar="addOrEditInspectionScopePersonnelInfo" width="450" height="200"
			header="中调联系人">
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="保存" icon="ui-icon-disk" 
						actionListener="#{addOrEditInspectSelfPlanController.saveOrUpdateInspectionScopePersonnelInfo}"
						oncomplete="PF('addOrEditInspectionScopePersonnelInfo').hide();setHeight()"
						update="inspectSelfTreeForm:inspectSelfInfo"/>
				</f:facet>
			</p:toolbar>
			<p:outputPanel style="text-align:center;">
				<p:panelGrid style="text-align:center;margin: 10px;width: 95%">
					<p:row>
						<p:column>
							<h:outputText value="联系人：" />
						</p:column>
						<p:column colspan="3">
							<h:inputText style="width:90%" value="#{addOrEditInspectSelfPlanController.inspectionScopePersonnel}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="联系电话：" />
						</p:column>
						<p:column colspan="3">
							<h:inputText style="width:90%" value="#{addOrEditInspectSelfPlanController.inspectionScopePersonnelPhone}" />
						</p:column>
					</p:row>
				</p:panelGrid>
			</p:outputPanel>
		</p:dialog>
	</h:form>
	</ui:define>
</ui:composition>